---@class GT.ui.control.input : GT.ui
---@field u table<RoleID,GT.ui.control.input> 玩家独立数据驱动
---@field binding GT.ui.control.input
GT.ui.control.input = class(GT.ui, false)


---@class ui_data_input : ui_data
---@field focus boolean 输入框焦点
ui_data_input = {
    focus = false
}

--- 创建图标
---@param data ui_data_input
---@return GT.ui.control.input
function GT.ui.control.input:ctor(data)
    data.class=GT.ui.control.input
    if data.uid ~= nil then
        super(self, data)
    else
        data.u_type = GT.ui.type.input_field
        self.focus = data.focus
        --创建控件
        super(self, data)
    end


    self:input_watch()
    return self
end

---转对象
---@param data ui_data_input
---@return GT.ui.control.input
function GT.ui.control.input.obj(data)
    return new(GT.ui.control.input, data)
end


--监听绑定
---@return GT.ui.control.input
function GT.ui.control.input:input_watch()
    ---@type bind_data[]
    local data = {
        {
            key = "focus",
            func = function(val, old)
                self.focus = val
                if self.focus then
                    self:set_focus()
                else
                    self:set_not_focus()
                end
            end
        }
    }

    self.bind:add(data)
    return self
end

--- 设置输入框获得焦点
---@return GT.ui.control.input
function GT.ui.control.input:set_focus()
    game_api.set_input_field_focus(self.player.player , self.uid)
    return self
end

--- 设置输入框失去焦点
---@return GT.ui.control.input
function GT.ui.control.input:set_not_focus()
    game_api.set_input_field_not_focus(self.player.player , self.uid)
    return self
end

--- 获得玩家输入框文本内容
---@return Str
function GT.ui.control.input:get_content()
    self.text = game_api.get_input_field_content(self.player.player , self.uid)
    return self.text
end
